<!DOCTYPE HTML>
<html lang="en">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="AverageJoe&#39;s Blog">
    <meta name="description" content="this is my secret garden where I sow my inspirations.">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>AverageJoe&#39;s Blog</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>
<meta name="generator" content="Hexo 5.0.0"><link rel="alternate" href="/atom.xml" title="AverageJoe's Blog" type="application/atom+xml">
</head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">AverageJoe&#39;s Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>Index</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>Tags</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>Categories</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>Archives</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>About</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>Contact</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>Friends</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="Search" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">AverageJoe&#39;s Blog</div>
        <div class="logo-desc">
            
            this is my secret garden where I sow my inspirations.
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			Index
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			Tags
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			Categories
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			Archives
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			About
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			Contact
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			Friends
		</a>
          
        </li>
        
        
    </ul>
</div>


        </div>

        
    </nav>

</header>

    
<script src="/libs/cryptojs/crypto-js.min.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('请输入访问本文章的密码')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误，将返回主页！');
                location.href = '/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/0.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title"></h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        height: calc(100vh - 250px);
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                          <div class="article-tag">
                            <span class="chip bg-color">No tag</span>
                          </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>Publish Date:&nbsp;&nbsp;
                    2018-08-18
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>Update Date:&nbsp;&nbsp;
                    2018-08-18
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>Word Count:&nbsp;&nbsp;
                    5.6k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>Read Times:&nbsp;&nbsp;
                    24 Min
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>Read Count:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="0-学习目标"><a href="#0-学习目标" class="headerlink" title="0.学习目标"></a>0.学习目标</h1><ul>
<li>会调用订单系统接口</li>
<li>实现订单结算功能</li>
<li>实现微信支付功能</li>
</ul>
<h1 id="1-订单系统接口"><a href="#1-订单系统接口" class="headerlink" title="1.订单系统接口"></a>1.订单系统接口</h1><p>我们不做开发，只讲解</p>
<h2 id="1-1-导入订单服务"><a href="#1-1-导入订单服务" class="headerlink" title="1.1.导入订单服务"></a>1.1.导入订单服务</h2><p>把课前资料提供的<code>leyou-order</code>复制到<code>D:\heima\code\leyou</code>目录。</p>
<p>然后在工程内导入：</p>
<p> <img src="assets/1527849592739.png" alt="1527849592739"></p>
<p>然后导入module：</p>
<p> <img src="assets/1527849713858.png" alt="1527849713858"></p>
<p>选择导入module：</p>
<p> <img src="assets/1527849755740.png" alt="1527849755740"></p>
<p>选择目录中的 <code>ly-order</code>：</p>
<p> <img src="assets/1527988253596.png" alt="1527988253596"></p>
<p>打开父工程leyou的pom文件，添加<code>ly-order</code>模块：</p>
<p><img src="assets/1527988384844.png" alt="1527988384844"></p>
<h2 id="1-2-Swagger-UI"><a href="#1-2-Swagger-UI" class="headerlink" title="1.2.Swagger-UI"></a>1.2.Swagger-UI</h2><p>丝袜哥</p>
<h3 id="1-2-1-什么是OpenAPI"><a href="#1-2-1-什么是OpenAPI" class="headerlink" title="1.2.1.什么是OpenAPI"></a>1.2.1.什么是OpenAPI</h3><p>随着互联网技术的发展，现在的网站架构基本都由原来的后端渲染，变成了：前端渲染、前后端分离的形态，而且前端技术和后端技术在各自的道路上越走越远。  前端和后端的唯一联系，变成了API接口；API文档变成了前后端开发人员联系的纽带，变得越来越重要。</p>
<p>没有API文档工具之前，大家都是手写API文档的，在什么地方书写的都有，而且API文档没有统一规范和格式，每个公司都不一样。这无疑给开发带来了灾难。</p>
<p>OpenAPI规范（OpenAPI Specification 简称OAS）是Linux基金会的一个项目，试图通过定义一种用来描述API格式或API定义的语言，来规范RESTful服务开发过程。目前V3.0版本的OpenAPI规范已经发布并开源在github上 。</p>
<p>官网：<a target="_blank" rel="noopener" href="https://github.com/OAI/OpenAPI-Specification">https://github.com/OAI/OpenAPI-Specification</a></p>
<h3 id="1-2-2-什么是swagger？"><a href="#1-2-2-什么是swagger？" class="headerlink" title="1.2.2.什么是swagger？"></a>1.2.2.什么是swagger？</h3><p>OpenAPI是一个编写API文档的规范，然而如果手动去编写OpenAPI规范的文档，是非常麻烦的。而Swagger就是一个实现了OpenAPI规范的工具集。</p>
<p>官网：<a target="_blank" rel="noopener" href="https://swagger.io/">https://swagger.io/</a></p>
<p>看官方的说明：</p>
<p> <img src="assets/1528724925709.png" alt="1528724925709"></p>
<p>Swagger包含的工具集：</p>
<ul>
<li><strong>Swagger编辑器：</strong> Swagger Editor允许您在浏览器中编辑YAML中的OpenAPI规范并实时预览文档。</li>
<li><strong>Swagger UI：</strong> Swagger UI是HTML，Javascript和CSS资产的集合，可以从符合OAS标准的API动态生成漂亮的文档。</li>
<li><strong>Swagger Codegen：</strong>允许根据OpenAPI规范自动生成API客户端库（SDK生成），服务器存根和文档。</li>
<li><strong>Swagger Parser：</strong>用于解析来自Java的OpenAPI定义的独立库</li>
<li><strong>Swagger Core：</strong>与Java相关的库，用于创建，使用和使用OpenAPI定义</li>
<li><strong>Swagger Inspector（免费）：</strong> API测试工具，可让您验证您的API并从现有API生成OpenAPI定义</li>
<li><strong>SwaggerHub（免费和商业）：</strong> API设计和文档，为使用OpenAPI的团队构建。</li>
</ul>
<h3 id="1-2-3-快速入门"><a href="#1-2-3-快速入门" class="headerlink" title="1.2.3.快速入门"></a>1.2.3.快速入门</h3><p>SpringBoot已经集成了Swagger，使用简单注解即可生成swagger的API文档。</p>
<h4 id="1）引入依赖"><a href="#1）引入依赖" class="headerlink" title="1）引入依赖"></a>1）引入依赖</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-swagger2<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.8.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-swagger-ui<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.8.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="2）编写配置"><a href="#2）编写配置" class="headerlink" title="2）编写配置"></a>2）编写配置</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableSwagger2</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SwaggerConfig</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Docket <span class="title">api</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Docket(DocumentationType.SWAGGER_2)</span><br><span class="line">                .host(<span class="string">&quot;http://order.leyou.com&quot;</span>)</span><br><span class="line">                .apiInfo(apiInfo())</span><br><span class="line">                .select()</span><br><span class="line">                .apis(RequestHandlerSelectors.basePackage(<span class="string">&quot;com.leyou.order.controller&quot;</span>))</span><br><span class="line">                .paths(PathSelectors.any())</span><br><span class="line">                .build();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> ApiInfo <span class="title">apiInfo</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> ApiInfoBuilder()</span><br><span class="line">                .title(<span class="string">&quot;乐优商城订单系统&quot;</span>)</span><br><span class="line">                .description(<span class="string">&quot;乐优商城订单系统接口文档&quot;</span>)</span><br><span class="line">                .version(<span class="string">&quot;1.0&quot;</span>)</span><br><span class="line">                .build();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="3）接口声明"><a href="#3）接口声明" class="headerlink" title="3）接口声明"></a>3）接口声明</h4><p>在controller的每个handler上添加接口说明注解：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping(&quot;order&quot;)</span></span><br><span class="line"><span class="meta">@Api(&quot;订单服务接口&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">OrderController</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> OrderService orderService;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> PayHelper payHelper;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 创建订单</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> order 订单对象</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 订单编号</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@PostMapping</span></span><br><span class="line">    <span class="meta">@ApiOperation(value = &quot;创建订单接口，返回订单编号&quot;, notes = &quot;创建订单&quot;)</span></span><br><span class="line">    <span class="meta">@ApiImplicitParam(name = &quot;order&quot;, required = true, value = &quot;订单的json对象,包含订单条目和物流信息&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> ResponseEntity&lt;Long&gt; <span class="title">createOrder</span><span class="params">(<span class="meta">@RequestBody</span> <span class="meta">@Valid</span> Order order)</span> </span>&#123;</span><br><span class="line">        Long id = <span class="keyword">this</span>.orderService.createOrder(order);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> ResponseEntity&lt;&gt;(id, HttpStatus.CREATED);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 分页查询当前用户订单</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> status 订单状态</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 分页订单数据</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@GetMapping(&quot;list&quot;)</span></span><br><span class="line">    <span class="meta">@ApiOperation(value = &quot;分页查询当前用户订单，并且可以根据订单状态过滤&quot;, </span></span><br><span class="line"><span class="meta">                  notes = &quot;分页查询当前用户订单&quot;)</span></span><br><span class="line">    <span class="meta">@ApiImplicitParams(&#123;</span></span><br><span class="line"><span class="meta">        @ApiImplicitParam(name = &quot;page&quot;, value = &quot;当前页&quot;, </span></span><br><span class="line"><span class="meta">                          defaultValue = &quot;1&quot;, type = &quot;Integer&quot;),</span></span><br><span class="line"><span class="meta">        @ApiImplicitParam(name = &quot;rows&quot;, value = &quot;每页大小&quot;, </span></span><br><span class="line"><span class="meta">                          defaultValue = &quot;5&quot;, type = &quot;Integer&quot;),</span></span><br><span class="line"><span class="meta">        @ApiImplicitParam(</span></span><br><span class="line"><span class="meta">            name = &quot;status&quot;, </span></span><br><span class="line"><span class="meta">            value = &quot;订单状态：1未付款，2已付款未发货，3已发货未确认，4已确认未评价，5交易关闭，6交易成功，已评价&quot;, type = &quot;Integer&quot;),</span></span><br><span class="line"><span class="meta">    &#125;)</span></span><br><span class="line">    <span class="keyword">public</span> ResponseEntity&lt;PageResult&lt;Order&gt;&gt; queryUserOrderList(</span><br><span class="line">        <span class="meta">@RequestParam(value = &quot;page&quot;, defaultValue = &quot;1&quot;)</span> Integer page,</span><br><span class="line">        <span class="meta">@RequestParam(value = &quot;rows&quot;, defaultValue = &quot;5&quot;)</span> Integer rows,</span><br><span class="line">        <span class="meta">@RequestParam(value = &quot;status&quot;, required = false)</span> Integer status) &#123;</span><br><span class="line">        PageResult&lt;Order&gt; result = <span class="keyword">this</span>.orderService.queryUserOrderList(page, rows, status);</span><br><span class="line">        <span class="keyword">if</span> (result == <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> ResponseEntity&lt;&gt;(HttpStatus.NOT_FOUND);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> ResponseEntity.ok(result);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>常用注解说明：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> <span class="doctag">@Api</span>：修饰整个类，描述Controller的作用</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiOperation</span>：描述一个类的一个方法，或者说一个接口</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiParam</span>：单个参数描述</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiModel</span>：用对象来接收参数</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiProperty</span>：用对象接收参数时，描述对象的一个字段</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiResponse</span>：HTTP响应其中1个描述</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiResponses</span>：HTTP响应整体描述</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiIgnore</span>：使用该注解忽略这个API</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiError</span> ：发生错误返回的信息</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiImplicitParam</span>：一个请求参数</span></span><br><span class="line"><span class="comment"> <span class="doctag">@ApiImplicitParams</span>：多个请求参数</span></span><br><span class="line"><span class="comment"> */</span></span><br></pre></td></tr></table></figure>

<h4 id="4）启动测试"><a href="#4）启动测试" class="headerlink" title="4）启动测试"></a>4）启动测试</h4><p>启动服务，然后访问：<a target="_blank" rel="noopener" href="http://localhost:8089/swagger-ui.html">http://localhost:8089/swagger-ui.html</a></p>
<p><img src="assets/1534050474425.png" alt="1534050474425"></p>
<p>点击order-controller，查看接口信息：</p>
<p><img src="assets/1534050501639.png" alt="1534050501639"></p>
<p>点击任意一个接口，即可看到详细信息：</p>
<p><img src="assets/1534050571547.png" alt="1534050571547"></p>
<h2 id="1-3-测试接口"><a href="#1-3-测试接口" class="headerlink" title="1.3.测试接口"></a>1.3.测试接口</h2><h3 id="1-3-1-创建订单接口"><a href="#1-3-1-创建订单接口" class="headerlink" title="1.3.1.创建订单接口"></a>1.3.1.创建订单接口</h3><p>可以通过页面看到接口信息：</p>
<ul>
<li>请求方式：POST</li>
<li>请求路径：/order</li>
<li>请求参数：包含订单、订单详情等数据的json对象。</li>
<li>返回结果：订单编号</li>
</ul>
<p>点击<code>Try It Out</code>来测试：</p>
<p><img src="assets/1528726383029.png" alt="1528726383029"></p>
<p>输入数据：</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">&quot;totalPay&quot;</span>: <span class="number">236800</span>,</span><br><span class="line">  <span class="attr">&quot;postFee&quot;</span>: <span class="number">0</span>,</span><br><span class="line">  <span class="attr">&quot;paymentType&quot;</span>: <span class="number">2</span>,</span><br><span class="line">  <span class="attr">&quot;actualPay&quot;</span>: <span class="number">236800</span>,</span><br><span class="line">  <span class="attr">&quot;buyerMessage&quot;</span>: <span class="literal">null</span>,</span><br><span class="line">  <span class="attr">&quot;buyerNick&quot;</span>: <span class="string">&quot;huge&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;orderDetails&quot;</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">&quot;skuId&quot;</span>: <span class="number">3893493</span>,</span><br><span class="line">      <span class="attr">&quot;num&quot;</span>: <span class="number">1</span>,</span><br><span class="line">      <span class="attr">&quot;title&quot;</span>: <span class="string">&quot;苹果（Apple）iPhone 6 (A1586) 16GB 金色 移动联通电信4G手机3&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;price&quot;</span>: <span class="number">236800</span>,</span><br><span class="line">      <span class="attr">&quot;ownSpec&quot;</span>: <span class="string">&quot;&#123;\&quot;机身颜色\&quot;:\&quot;钻雕蓝\&quot;,\&quot;内存\&quot;:\&quot;4GB\&quot;,\&quot;机身存储\&quot;:\&quot;64GB\&quot;&#125;&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;image&quot;</span>: <span class="string">&quot;http://image.leyou.com/images/9/4/1524297342728.jpg&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">&quot;receiver&quot;</span>: <span class="string">&quot;锋哥&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;receiverMobile&quot;</span>: <span class="string">&quot;15800000000&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;receiverState&quot;</span>: <span class="string">&quot;上海&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;receiverCity&quot;</span>: <span class="string">&quot;上海&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;receiverDistrict&quot;</span>: <span class="string">&quot;浦东新签&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;receiverAddress&quot;</span>: <span class="string">&quot;航头镇航头路18号传智播客3号楼&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;receiverZip&quot;</span>: <span class="string">&quot;210000&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;invoiceType&quot;</span>: <span class="number">0</span>,</span><br><span class="line">  <span class="attr">&quot;sourceType&quot;</span>:<span class="number">2</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>然后点击execute：</p>
<p><img src="assets/1534050960735.png" alt="1534050960735"></p>
<p>结果：</p>
<p><img src="assets/1534056625226.png" alt="1534056625226"></p>
<p>下单需要登录，通过登录生成token：</p>
<p><img src="assets/1534056963545.png" alt="1534056963545"></p>
<p>把token的值手动加入到浏览器的cookie中：</p>
<p><img src="assets/1534057111628.png" alt="1534057111628"></p>
<p><img src="assets/1534057197865.png" alt="1534057197865"></p>
<p>添加成功，响应订单编号。但是和数据库保存的订单编号不太一样（后几位不一样，浏览器展示长整型会出现精度损失）</p>
<h3 id="1-3-2-生成ID的方式"><a href="#1-3-2-生成ID的方式" class="headerlink" title="1.3.2.生成ID的方式"></a>1.3.2.生成ID的方式</h3><blockquote>
<p>订单id的特殊性</p>
</blockquote>
<p>订单数据非常庞大，将来一定会做分库分表。那么这种情况下， 要保证id的唯一，就不能靠数据库自增，而是自己来实现算法，生成唯一id。</p>
<blockquote>
<p>雪花算法</p>
</blockquote>
<p>这里的订单id是通过一个工具类生成的：</p>
<p> <img src="assets/1534057752285.png" alt="1534057752285"></p>
<p>而工具类所采用的生成id算法，是由Twitter公司开源的snowflake（雪花）算法。</p>
<blockquote>
<p>简单原理</p>
</blockquote>
<p>雪花算法会生成一个64位的二进制数据，为一个Long型。(转换成字符串后长度最多19位) ，其基本结构：</p>
<p> <img src="assets/1528729105237.png" alt="1528729105237"></p>
<p>第一位：为未使用</p>
<p>第二部分：41位为毫秒级时间(41位的长度可以使用69年)</p>
<p>第三部分：5位datacenterId和5位workerId(10位的长度最多支持部署1024个节点）</p>
<p>第四部分：最后12位是毫秒内的计数（12位的计数顺序号支持每个节点每毫秒产生4096个ID序号）</p>
<p>snowflake生成的ID整体上按照时间自增排序，并且整个分布式系统内不会产生ID碰撞（由datacenter和workerId作区分），并且效率较高。经测试snowflake每秒能够产生26万个ID。</p>
<blockquote>
<p>配置</p>
</blockquote>
<p>为了保证不重复，我们给每个部署的节点都配置机器id：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">leyou:</span></span><br><span class="line">  <span class="attr">worker:</span></span><br><span class="line">    <span class="attr">workerId:</span> <span class="number">1</span></span><br><span class="line">    <span class="attr">datacenterId:</span> <span class="number">1</span></span><br></pre></td></tr></table></figure>

<p>加载属性：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ConfigurationProperties(prefix = &quot;leyou.worker&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">IdWorkerProperties</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">long</span> workerId;<span class="comment">// 当前机器id</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">long</span> datacenterId;<span class="comment">// 序列号</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">getWorkerId</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> workerId;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setWorkerId</span><span class="params">(<span class="keyword">long</span> workerId)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.workerId = workerId;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">long</span> <span class="title">getDatacenterId</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> datacenterId;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setDatacenterId</span><span class="params">(<span class="keyword">long</span> datacenterId)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.datacenterId = datacenterId;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>编写配置类：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableConfigurationProperties(IdWorkerProperties.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">IdWorkerConfig</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> IdWorker <span class="title">idWorker</span><span class="params">(IdWorkerProperties prop)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> IdWorker(prop.getWorkerId(), prop.getDatacenterId());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>使用：</p>
</blockquote>
<p><img src="assets/1534057869509.png" alt="1534057869509"></p>
<h3 id="1-3-2-查询订单接口"><a href="#1-3-2-查询订单接口" class="headerlink" title="1.3.2.查询订单接口"></a>1.3.2.查询订单接口</h3><p>接口说明：</p>
<ul>
<li>请求方式：GET</li>
<li>请求路径：/order/{id}</li>
<li>请求参数：id，订单编号</li>
<li>返回结果：Order，订单的json对象</li>
</ul>
<p>测试：</p>
<p><img src="assets/1534058725566.png" alt="1534058725566"></p>
<p>结果：</p>
<p><img src="assets/1534058696076.png" alt="1534058696076"></p>
<h3 id="1-3-3-更新订单状态"><a href="#1-3-3-更新订单状态" class="headerlink" title="1.3.3.更新订单状态"></a>1.3.3.更新订单状态</h3><p>接口说明：</p>
<ul>
<li>请求参数：PUT</li>
<li>请求路径：/order/{id}/{status}</li>
<li>请求参数：<ul>
<li>id：订单编号，String类型，不能为空</li>
<li>status：订单状态，不能为空</li>
</ul>
</li>
<li>返回结果：null</li>
</ul>
<p>测试：</p>
<p><img src="assets/1534059150417.png" alt="1534059150417"></p>
<p>结果：</p>
<p><img src="assets/1534059488506.png" alt="1534059488506"></p>
<p>数据库中也发生了改变：</p>
<p><img src="assets/1534059550338.png" alt="1534059550338"></p>
<h3 id="1-3-4-分页查询订单"><a href="#1-3-4-分页查询订单" class="headerlink" title="1.3.4.分页查询订单"></a>1.3.4.分页查询订单</h3><p>接口说明：</p>
<ul>
<li>请求方式：Get</li>
<li>请求路径：/order/list</li>
<li>请求参数：<ul>
<li>page：当前页，Integer类型，默认为1</li>
<li>rows：每页大小，Integer类型，默认为5</li>
<li>status：订单状态，String类型，默认查询全部状态订单</li>
</ul>
</li>
<li>返回结果：PageResult   对象，包含下面属性：<ul>
<li>total：总条数</li>
<li>items：当前页订单数组<ul>
<li>订单对象</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>测试：</p>
<p><img src="assets/1534059762431.png" alt="1534059762431"></p>
<p>结果：</p>
<p><img src="assets/1534059802562.png" alt="1534059802562"></p>
<h3 id="1-3-5-生成微信付款链接"><a href="#1-3-5-生成微信付款链接" class="headerlink" title="1.3.5.生成微信付款链接"></a>1.3.5.生成微信付款链接</h3><p>接口说明：</p>
<ul>
<li>请求方式：Get</li>
<li>请求路径：/order/url/{id}</li>
<li>请求参数：id，订单编号</li>
<li>返回结果：String类型，生成的微信支付链接</li>
</ul>
<p>测试：</p>
<p><img src="assets/1534059974834.png" alt="1534059974834"></p>
<p>结果：</p>
<p><img src="assets/1534060051812.png" alt="1534060051812"></p>
<h4 id="微信支付工具"><a href="#微信支付工具" class="headerlink" title="微信支付工具"></a>微信支付工具</h4><blockquote>
<p>PayHelper</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">PayHelper</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> WXPay wxPay;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> Logger logger = LoggerFactory.getLogger(PayHelper.class);</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> StringRedisTemplate redisTemplate;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> OrderService orderService;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">PayHelper</span><span class="params">(PayConfig payConfig)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// 真实开发时</span></span><br><span class="line">        wxPay = <span class="keyword">new</span> WXPay(payConfig);</span><br><span class="line">        <span class="comment">// 测试时</span></span><br><span class="line">        <span class="comment">// wxPay = new WXPay(payConfig, WXPayConstants.SignType.MD5, true);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">createPayUrl</span><span class="params">(Long orderId)</span> </span>&#123;</span><br><span class="line">        String key = <span class="string">&quot;ly.pay.url.&quot;</span> + orderId;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            String url = <span class="keyword">this</span>.redisTemplate.opsForValue().get(key);</span><br><span class="line">            <span class="keyword">if</span> (StringUtils.isNotBlank(url)) &#123;</span><br><span class="line">                <span class="keyword">return</span> url;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            logger.error(<span class="string">&quot;查询缓存付款链接异常,订单编号：&#123;&#125;&quot;</span>, orderId, e);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Map&lt;String, String&gt; data = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">            <span class="comment">// 商品描述</span></span><br><span class="line">            data.put(<span class="string">&quot;body&quot;</span>, <span class="string">&quot;乐优商城测试&quot;</span>);</span><br><span class="line">            <span class="comment">// 订单号</span></span><br><span class="line">            data.put(<span class="string">&quot;out_trade_no&quot;</span>, orderId.toString());</span><br><span class="line">            <span class="comment">//货币</span></span><br><span class="line">            data.put(<span class="string">&quot;fee_type&quot;</span>, <span class="string">&quot;CNY&quot;</span>);</span><br><span class="line">            <span class="comment">//金额，单位是分</span></span><br><span class="line">            data.put(<span class="string">&quot;total_fee&quot;</span>, <span class="string">&quot;1&quot;</span>);</span><br><span class="line">            <span class="comment">//调用微信支付的终端IP（estore商城的IP）</span></span><br><span class="line">            data.put(<span class="string">&quot;spbill_create_ip&quot;</span>, <span class="string">&quot;127.0.0.1&quot;</span>);</span><br><span class="line">            <span class="comment">//回调地址</span></span><br><span class="line">            data.put(<span class="string">&quot;notify_url&quot;</span>, <span class="string">&quot;http://test.leyou.com/wxpay/notify&quot;</span>);</span><br><span class="line">            <span class="comment">// 交易类型为扫码支付</span></span><br><span class="line">            data.put(<span class="string">&quot;trade_type&quot;</span>, <span class="string">&quot;NATIVE&quot;</span>);</span><br><span class="line">            <span class="comment">//商品id,使用假数据</span></span><br><span class="line">            data.put(<span class="string">&quot;product_id&quot;</span>, <span class="string">&quot;1234567&quot;</span>);</span><br><span class="line"></span><br><span class="line">            Map&lt;String, String&gt; result = <span class="keyword">this</span>.wxPay.unifiedOrder(data);</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (<span class="string">&quot;SUCCESS&quot;</span>.equals(result.get(<span class="string">&quot;return_code&quot;</span>))) &#123;</span><br><span class="line">                String url = result.get(<span class="string">&quot;code_url&quot;</span>);</span><br><span class="line">                <span class="comment">// 将付款地址缓存，时间为10分钟</span></span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    <span class="keyword">this</span>.redisTemplate.opsForValue().set(key, url, <span class="number">10</span>, TimeUnit.MINUTES);</span><br><span class="line">                &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">                    logger.error(<span class="string">&quot;缓存付款链接异常,订单编号：&#123;&#125;&quot;</span>, orderId, e);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> url;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                logger.error(<span class="string">&quot;创建预交易订单失败，错误信息：&#123;&#125;&quot;</span>, result.get(<span class="string">&quot;return_msg&quot;</span>));</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            logger.error(<span class="string">&quot;创建预交易订单异常&quot;</span>, e);</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 查询订单状态</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> orderId</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> PayState <span class="title">queryOrder</span><span class="params">(Long orderId)</span> </span>&#123;</span><br><span class="line">        Map&lt;String, String&gt; data = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">        <span class="comment">// 订单号</span></span><br><span class="line">        data.put(<span class="string">&quot;out_trade_no&quot;</span>, orderId.toString());</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Map&lt;String, String&gt; result = <span class="keyword">this</span>.wxPay.orderQuery(data);</span><br><span class="line">            <span class="keyword">if</span> (result == <span class="keyword">null</span>) &#123;</span><br><span class="line">                <span class="comment">// 未查询到结果，认为是未付款</span></span><br><span class="line">                <span class="keyword">return</span> PayState.NOT_PAY;</span><br><span class="line">            &#125;</span><br><span class="line">            String state = result.get(<span class="string">&quot;trade_state&quot;</span>);</span><br><span class="line">            <span class="keyword">if</span> (<span class="string">&quot;SUCCESS&quot;</span>.equals(state)) &#123;</span><br><span class="line">                <span class="comment">// success，则认为付款成功</span></span><br><span class="line"></span><br><span class="line">                <span class="comment">// 修改订单状态</span></span><br><span class="line">                <span class="keyword">this</span>.orderService.updateStatus(orderId, <span class="number">2</span>);</span><br><span class="line">                <span class="keyword">return</span> PayState.SUCCESS;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (StringUtils.equals(<span class="string">&quot;USERPAYING&quot;</span>, state)</span><br><span class="line">                       || StringUtils.equals(<span class="string">&quot;NOTPAY&quot;</span>, state)) &#123;</span><br><span class="line">                <span class="comment">// 未付款或正在付款，都认为是未付款</span></span><br><span class="line">                <span class="keyword">return</span> PayState.NOT_PAY;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">// 其它状态认为是付款失败</span></span><br><span class="line">                <span class="keyword">return</span> PayState.FAIL;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            logger.error(<span class="string">&quot;查询订单状态异常&quot;</span>, e);</span><br><span class="line">            <span class="keyword">return</span> PayState.NOT_PAY;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>跟支付相关的其它几个类：</p>
<p> <img src="assets/1528796883071.png" alt="1528796883071"></p>
<h3 id="1-3-6-查询支付状态"><a href="#1-3-6-查询支付状态" class="headerlink" title="1.3.6.查询支付状态"></a>1.3.6.查询支付状态</h3><p>接口说明：</p>
<ul>
<li>请求方式： Get</li>
<li>请求路径： /state/{id}</li>
<li>请求参数： id，订单编号</li>
<li>返回结果：0, 未查询到支付信息 1,支付成功 2,支付失败（查询失败，或者订单过期）</li>
</ul>
<h4 id="1-3-6-1-未付款"><a href="#1-3-6-1-未付款" class="headerlink" title="1.3.6.1.未付款"></a>1.3.6.1.未付款</h4><p>未付款时查询，测试：</p>
<p><img src="assets/1534060875467.png" alt="1534060875467"></p>
<p>结果：</p>
<p><img src="assets/1534061834503.png" alt="1534061834503"></p>
<p>因为尚未付款，所以查询返回0。</p>
<h4 id="1-3-6-2-付款"><a href="#1-3-6-2-付款" class="headerlink" title="1.3.6.2.付款"></a>1.3.6.2.付款</h4><p>通过JS把链接变成二维码。</p>
<p>找到课前资料提供的JS页面：</p>
<p><img src="assets/1534061965270.png" alt="1534061965270"></p>
<p>进入，并输入刚刚生成的地址：</p>
<p><img src="assets/1534062028046.png" alt="1534062028046"></p>
<h4 id="1-3-6-3-已付款"><a href="#1-3-6-3-已付款" class="headerlink" title="1.3.6.3.已付款"></a>1.3.6.3.已付款</h4><p>扫码支付，然后再次查询：</p>
<p><img src="assets/1534062115599.png" alt="1534062115599"></p>
<p>状态码为1，代表支付成功了！</p>
<h1 id="2-订单结算页"><a href="#2-订单结算页" class="headerlink" title="2.订单结算页"></a>2.订单结算页</h1><h2 id="2-1-页面跳转"><a href="#2-1-页面跳转" class="headerlink" title="2.1.页面跳转"></a>2.1.页面跳转</h2><p>在购物车页面的最下方，有一个去结算按钮：</p>
<p><img src="assets/1527990452791.png" alt="1527990452791"></p>
<p>当点击结算，我们应该跳转到订单结算页，即：<code>getOrderInfo.html</code></p>
<p> <img src="assets/1534062458952.png" alt="1534062458952"></p>
<p>查看购物车的<code>结算</code>按钮：</p>
<p><img src="assets/1534063127883.png" alt="1534063127883"></p>
<p>可以看到，地址是正确的。但是只有登录用户才可以去结算付款，因此我们不能直接跳转，而是在跳转前校验用户的登录状态，如果发现是未登录，应该重定向到登录页！</p>
<p>我们给这个按钮绑定点击事件：</p>
<p><img src="assets/1534063368728.png" alt="1534063368728"></p>
<p>事件中判断登录状态，进行页面跳转：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">toOrderInfo() &#123;</span><br><span class="line">    <span class="comment">// 判断是否登录</span></span><br><span class="line">    ly.verifyUser().then(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// 已登录</span></span><br><span class="line">        <span class="built_in">window</span>.location.href = <span class="string">&quot;/getOrderInfo.html&quot;</span></span><br><span class="line">    &#125;).catch(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// 未登录</span></span><br><span class="line">        <span class="built_in">window</span>.location.href = <span class="string">&quot;/login.html?returnUrl=&quot;</span> + <span class="built_in">window</span>.location.href;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>登录后测试：</p>
<p><img src="assets/1534068627040.png" alt="1534068627040"></p>
<p>此处页面需要渲染的内容主要包含3部分：</p>
<ul>
<li>收货人信息</li>
<li>支付方式</li>
<li>商品信息</li>
</ul>
<h2 id="2-2-收货人信息（作业）"><a href="#2-2-收货人信息（作业）" class="headerlink" title="2.2.收货人信息（作业）"></a>2.2.收货人信息（作业）</h2><p><img src="assets/1528011713709.png" alt="1528011713709"></p>
<p>这里的收货人信息肯定是当前登录用户的收货地址。所以需要根据当前登录用户去查询，目前我们在页面是写的假数据：</p>
<p><img src="assets/1534070259673.png" alt="1534070259673"></p>
<p>大家可以在在后台提供地址的增删改查接口，然后页面加载时根据当前登录用户查询，而后赋值给addresses即可。</p>
<h2 id="2-3-支付方式"><a href="#2-3-支付方式" class="headerlink" title="2.3.支付方式"></a>2.3.支付方式</h2><p>支付方式有2种：</p>
<ul>
<li>微信支付</li>
<li>货到付款</li>
</ul>
<p>与我们订单数据中的<code>paymentType</code>关联：</p>
<p><img src="assets/1528012065388.png" alt="1528012065388"></p>
<p>所以我们可以在Vue实例中定义一个属性来记录支付方式：</p>
<p><img src="assets/1534070467947.png" alt="1534070467947"></p>
<p>然后在页面渲染时与这个变量关联：</p>
<p><img src="assets/1534070743780.png" alt="1534070743780"></p>
<h2 id="2-4-商品列表"><a href="#2-4-商品列表" class="headerlink" title="2.4.商品列表"></a>2.4.商品列表</h2><p>效果图：</p>
<p><img src="assets/1528012881735.png" alt="1528012881735"></p>
<p>这里的送货清单，其实就是购物车中用户选择的要付款的商品</p>
<p>因此，我们需要在购物车跳转过来的同时，携带选中的购物车的信息</p>
<h3 id="2-4-1-购物车信息获取"><a href="#2-4-1-购物车信息获取" class="headerlink" title="2.4.1.购物车信息获取"></a>2.4.1.购物车信息获取</h3><p>我们修改<code>cart.html</code>中的页面跳转逻辑，把用户选中的购物车信息传递过来：</p>
<p><img src="assets/1534071010391.png" alt="1534071010391"></p>
<p>然后在<code>created</code>钩子函数中获取购物车数据，保存到本地属性，要注意的是，我们应该在获取数据前校验用户登录状态，如果发现未登录，则直接重定向到登录页：</p>
<p><img src="assets/1534071493245.png" alt="1534071493245"></p>
<p>然后重新加载页面，查看控制台：</p>
<p><img src="assets/1534071647717.png" alt="1534071647717"></p>
<h3 id="2-4-2-页面渲染"><a href="#2-4-2-页面渲染" class="headerlink" title="2.4.2.页面渲染"></a>2.4.2.页面渲染</h3><p>要修改的页面位置：每一个li就是一件商品</p>
<p><img src="assets/1534071794146.png" alt="1534071794146"></p>
<p>我们修改为：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">ul</span> <span class="attr">class</span>=<span class="string">&quot;send-detail&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span> <span class="attr">v-for</span>=<span class="string">&quot;(cart,index) in carts&quot;</span> <span class="attr">:key</span>=<span class="string">&quot;index&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;sendGoods&quot;</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">ul</span> <span class="attr">class</span>=<span class="string">&quot;yui3-g&quot;</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;yui3-u-1-6&quot;</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">span</span>&gt;</span><span class="tag">&lt;<span class="name">img</span> <span class="attr">width</span>=<span class="string">&quot;70px&quot;</span> <span class="attr">height</span>=<span class="string">&quot;70px&quot;</span> <span class="attr">:src</span>=<span class="string">&quot;cart.image&quot;</span>/&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;yui3-u-7-12&quot;</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;desc&quot;</span>&gt;</span>&#123;&#123;cart.title&#125;&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;seven&quot;</span>&gt;</span></span><br><span class="line">                        <span class="tag">&lt;<span class="name">span</span> <span class="attr">v-for</span>=<span class="string">&quot;(v) in JSON.parse(cart.ownSpec)&quot;</span>&gt;</span>&#123;&#123;v + &quot;  &quot;&#125;&#125; <span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;yui3-u-1-12&quot;</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;price&quot;</span>&gt;</span>￥&#123;&#123;ly.formatPrice(cart.price * cart.num)&#125;&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;yui3-u-1-12&quot;</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;num&quot;</span>&gt;</span>&#123;&#123;cart.num&#125;&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">&quot;yui3-u-1-12&quot;</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;exit&quot;</span>&gt;</span>有货<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h2 id="2-5-总金额"><a href="#2-5-总金额" class="headerlink" title="2.5.总金额"></a>2.5.总金额</h2><p>另外在商品列表下面，还有一个总金额的计算：</p>
<p><img src="assets/1534072483208.png" alt="1534072483208"></p>
<p>可以看出这里主要有4个数据：</p>
<ul>
<li>总金额：totalPay</li>
<li>优惠返现：discount</li>
<li>运费：postFee</li>
<li>实付金额：actualPay</li>
</ul>
<p>不过我们没有做优惠活动，另外运费需要结合物流系统来计算，暂时我们都设置为0，在order属性中写死：</p>
<p><img src="assets/1534072753146.png" alt="1534072753146"></p>
<p>我们通过计算属性来得到<code>totalPay</code>和<code>actualPay</code>值：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">computed: &#123;</span><br><span class="line">    totalNum()&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">this</span>.carts.reduce(<span class="function">(<span class="params">c1, c2</span>) =&gt;</span> c1 + c2.num, <span class="number">0</span>)</span><br><span class="line">    &#125;,</span><br><span class="line">    totalPay()&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">this</span>.carts.reduce(<span class="function">(<span class="params">c1, c2</span>) =&gt;</span> c1 + c2.price * c2.num, <span class="number">0</span>);</span><br><span class="line">    &#125;,</span><br><span class="line">    actualPay()&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">this</span>.totalPay + <span class="built_in">this</span>.order.postFee - <span class="built_in">this</span>.order.discount;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>

<p>然后在页面渲染：</p>
<p><img src="assets/1534073678931.png" alt="1534073678931"></p>
<p>效果：</p>
<p><img src="assets/1534073704731.png" alt="1534073704731"></p>
<h2 id="2-6-提交订单"><a href="#2-6-提交订单" class="headerlink" title="2.6.提交订单"></a>2.6.提交订单</h2><h3 id="2-6-1-页面提交"><a href="#2-6-1-页面提交" class="headerlink" title="2.6.1.页面提交"></a>2.6.1.页面提交</h3><p>来看下订单接口所需要的数据：</p>
<p><img src="assets/1534074122199.png" alt="1534074122199"></p>
<p>分为3部分，分别是</p>
<ul>
<li><p>订单本身的基本信息</p>
<ul>
<li>总金额</li>
<li>实付金额</li>
<li>付款类型</li>
<li>买家信息就是当前用户</li>
</ul>
</li>
<li><p>订单详情</p>
<ul>
<li>就是购物车中的商品，不过购物车数据会多出一个userId，我们去除即可：</li>
</ul>
<p><img src="assets/1534074293296.png" alt="1534074293296"></p>
</li>
<li><p>物流信息</p>
<ul>
<li>当前用户选中的物流地址信息</li>
</ul>
</li>
</ul>
<p>给提交按钮绑定事件：</p>
<p><img src="assets/1534074374101.png" alt="1534074374101"></p>
<p>然后编写方法，组织数据并提交：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">methods: &#123;</span><br><span class="line">    submit() &#123;</span><br><span class="line">        <span class="comment">// 把购物车数据处理成订单详情</span></span><br><span class="line">        <span class="keyword">const</span> orderDetails = <span class="built_in">this</span>.carts.map(<span class="function">(<span class="params">&#123;userId, ...rest&#125;</span>) =&gt;</span> rest);</span><br><span class="line">        <span class="comment">// 处理物流信息</span></span><br><span class="line">        <span class="keyword">const</span> addr = <span class="built_in">this</span>.addresses[<span class="built_in">this</span>.selectedAddress];</span><br><span class="line">        <span class="keyword">const</span> obj = &#123;</span><br><span class="line">            receiver: addr.name,</span><br><span class="line">            receiverState: addr.state,</span><br><span class="line">            receiverCity: addr.city,</span><br><span class="line">            receiverAddress: addr.address,</span><br><span class="line">            receiverDistrict: addr.district,</span><br><span class="line">            receiverMobile: addr.phone,</span><br><span class="line">            receiverZip: addr.zipCode</span><br><span class="line">        &#125;;</span><br><span class="line">        <span class="comment">// 复制到订单对象</span></span><br><span class="line">        <span class="built_in">Object</span>.assign(<span class="built_in">this</span>.order, obj, &#123;</span><br><span class="line">            orderDetails,</span><br><span class="line">            totalPay: <span class="built_in">this</span>.totalPay,</span><br><span class="line">            actualPay: <span class="built_in">this</span>.actualPay,</span><br><span class="line">        &#125;);</span><br><span class="line">        <span class="comment">// 提交订单</span></span><br><span class="line">        ly.http.post(<span class="string">&quot;/order&quot;</span>, <span class="built_in">this</span>.order).then(<span class="function">(<span class="params">&#123;data&#125;</span>) =&gt;</span> &#123;</span><br><span class="line">            <span class="comment">// 在线支付，需要到付款页</span></span><br><span class="line">            <span class="built_in">window</span>.location = <span class="string">&quot;pay.html?orderId=&quot;</span> + data;</span><br><span class="line">        &#125;).catch(<span class="function">(<span class="params">resp</span>) =&gt;</span> &#123;</span><br><span class="line">            alert(<span class="string">&quot;订单提交失败，可能是缺货!&quot;</span>)</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>

<h3 id="2-6-2-精度损失问题"><a href="#2-6-2-精度损失问题" class="headerlink" title="2.6.2.精度损失问题"></a>2.6.2.精度损失问题</h3><p>在页面点击提交测试：</p>
<p> <img src="assets/1528340102503.png" alt="1528340102503"></p>
<p>成功生成订单！</p>
<p>然后看页面跳转：</p>
<p> <img src="assets/1528340136603.png" alt="1528340136603"></p>
<p>好像有什么不对？订单号的最后2位不正确啊！</p>
<p>这其实是因为JS的长整数精度有限，java的Long类型数据超出了范围，所以出现了精度损失。</p>
<p>我们后台返回的是Json的字符串，在axios内部会自动调用 JSON.parse()方法把json字符串转为JS数据，就会出现进度损失。如果不进行转换，依然当做字符串来使用，就不会有问题了。</p>
<p>因此，我们重写axios对响应的处理回调函数：</p>
<p> <img src="assets/1528340413139.png" alt="1528340413139"></p>
<p>再次测试，就OK了。</p>
<p>接下来就轮到支付了。</p>
<h1 id="3-微信支付"><a href="#3-微信支付" class="headerlink" title="3.微信支付"></a>3.微信支付</h1><h2 id="3-1-介绍"><a href="#3-1-介绍" class="headerlink" title="3.1.介绍"></a>3.1.介绍</h2><p>微信支付官方文档：<a target="_blank" rel="noopener" href="https://pay.weixin.qq.com/index.php/core/home/login?return_url=/">https://pay.weixin.qq.com/index.php/core/home/login?return_url=%2F</a></p>
<p><img src="assets/1527848350188.png" alt="1527848350188"></p>
<p>我们选择开发文档，而后进入选择页面：</p>
<p><img src="assets/1527848358128.png" alt="1527848358128"></p>
<p>选择扫码支付：</p>
<p><img src="assets/1527848368179.png" alt="1527848368179"></p>
<p>此处我们使用模式二来开发：</p>
<h2 id="3-2-开发流程"><a href="#3-2-开发流程" class="headerlink" title="3.2.开发流程"></a>3.2.开发流程</h2><p>模式二与模式一相比，流程更为简单，不依赖设置的回调支付URL。</p>
<p>商户后台系统先调用微信支付的统一下单接口，微信后台系统返回链接参数code_url；</p>
<p>商户后台系统将code_url值生成二维码图片，用户使用微信客户端扫码后发起支付。</p>
<p>注意：code_url有效期为2小时，过期后扫码不能再发起支付。 </p>
<p>流程图：</p>
<p><img src="assets/chapter6_5_1.png" alt="2wa23131"></p>
<p>这里我们把商户（我们）要做的事情总结一下：</p>
<ul>
<li>1、商户生成订单</li>
<li>2、商户调用微信下单接口，获取预交易的链接</li>
<li>3、商户将链接生成二维码图片，展示给用户；</li>
<li>4、用户支付并确认</li>
<li>5、支付结果通知：<ul>
<li>微信异步通知商户支付结果，商户告知微信支付接收情况</li>
<li>商户如果没有收到通知，可以调用接口，查询支付状态</li>
</ul>
</li>
<li>6、如果支付成功，发货，修改订单状态</li>
</ul>
<p>在前面的业务中，我们已经完成了：</p>
<ul>
<li>1、生成订单</li>
</ul>
<p>接下来，我们需要做的是：</p>
<ul>
<li>2、调用微信接口，生成链接。</li>
<li>3、并且生成二维码图片</li>
</ul>
<h2 id="3-3-生成二维码"><a href="#3-3-生成二维码" class="headerlink" title="3.3.生成二维码"></a>3.3.生成二维码</h2><h3 id="3-3-1-生成预交易链接"><a href="#3-3-1-生成预交易链接" class="headerlink" title="3.3.1.生成预交易链接"></a>3.3.1.生成预交易链接</h3><p>我们先根据订单的编号，调用后台服务，生成交易链接，而后才能根据链接生成二维码。</p>
<p>在页面发起请求：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> payVm = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">    el:<span class="string">&quot;#payVm&quot;</span>,</span><br><span class="line">    data:&#123;</span><br><span class="line">        ly,</span><br><span class="line">        orderId:<span class="number">0</span>,<span class="comment">// 订单编号</span></span><br><span class="line">    &#125;,</span><br><span class="line">    created()&#123;</span><br><span class="line">        <span class="comment">// 判断登录状态</span></span><br><span class="line">        ly.http.get(<span class="string">&quot;/auth/verify&quot;</span>).then(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">            <span class="comment">// 获取订单编号</span></span><br><span class="line">            <span class="built_in">this</span>.orderId = ly.getUrlParam(<span class="string">&quot;orderId&quot;</span>);</span><br><span class="line">            <span class="comment">// 获取请求链接</span></span><br><span class="line">            ly.http.get(<span class="string">&quot;/order/url/&quot;</span> + <span class="built_in">this</span>.orderId)</span><br><span class="line">                .then(<span class="function"><span class="params">resp</span> =&gt;</span> &#123;</span><br><span class="line">                    <span class="built_in">console</span>.log(resp.data);</span><br><span class="line">                &#125;)</span><br><span class="line">        &#125;.catch(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">            <span class="comment">// 未登录，跳转至登录页</span></span><br><span class="line">             location.href = <span class="string">&quot;/login.html?returnUrl=&quot;</span> + location.href;</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    components: &#123;</span><br><span class="line">        shortcut: <span class="function">() =&gt;</span> <span class="keyword">import</span>(<span class="string">&quot;./js/pages/shortcut.js&quot;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>后台已经定义好生成付款地址的接口。</p>
<p> <img src="assets/1528362159620.png" alt="1528362159620"></p>
<p>刷新页面查看：</p>
<p> <img src="assets/1528362220886.png" alt="1528362220886"></p>
<h3 id="3-3-2-生成二维码"><a href="#3-3-2-生成二维码" class="headerlink" title="3.3.2.生成二维码"></a>3.3.2.生成二维码</h3><p>这里我们使用一个生成二维码的JS插件：qrcode，官网：<a target="_blank" rel="noopener" href="https://github.com/davidshimjs/qrcodejs">https://github.com/davidshimjs/qrcodejs</a></p>
<p><img src="assets/1534313526721.png" alt="1534313526721"></p>
<p>我们把课这个js脚本引入到项目中：</p>
<p> <img src="assets/1528362348399.png" alt="1528362348399"></p>
<p>官方使用案例：</p>
<p><img src="assets/1534313925398.png" alt="1534313925398"></p>
<p>然后在页面引用：</p>
<p> <img src="assets/1528362377494.png" alt="1528362377494"></p>
<p>页面定义一个div，用于展示二维码：</p>
<p> <img src="assets/1528362023061.png" alt="1528362023061"></p>
<p>然后获取到付款链接后，根据链接生成二维码：</p>
<p> <img src="assets/1528362420151.png" alt="1528362420151"></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 判断登录状态</span></span><br><span class="line">ly.http.get(<span class="string">&quot;/auth/verify&quot;</span>).then(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 获取订单编号</span></span><br><span class="line">    <span class="built_in">this</span>.orderId = ly.getUrlParam(<span class="string">&quot;orderId&quot;</span>);</span><br><span class="line">    <span class="comment">// 获取请求链接</span></span><br><span class="line">    ly.http.get(<span class="string">&quot;/order/url/&quot;</span> + <span class="built_in">this</span>.orderId)</span><br><span class="line">        .then(<span class="function"><span class="params">resp</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">new</span> QRCode(<span class="built_in">document</span>.getElementById(<span class="string">&quot;qrImage&quot;</span>), &#123;</span><br><span class="line">                text: resp.data,</span><br><span class="line">                width: <span class="number">250</span>,</span><br><span class="line">                height: <span class="number">250</span>,</span><br><span class="line">                colorDark: <span class="string">&quot;#000000&quot;</span>,</span><br><span class="line">                colorLight: <span class="string">&quot;#ffffff&quot;</span>,</span><br><span class="line">                correctLevel: QRCode.CorrectLevel.H</span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;)</span><br><span class="line">&#125;).catch(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 未登录，跳转至登录页</span></span><br><span class="line">    location.href = <span class="string">&quot;/login.html?returnUrl=&quot;</span> + location.href;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<p>刷新页面，查看效果：</p>
<p> <img src="assets/1528362464276.png" alt="1528362464276"></p>
<p>此时，客户用手机扫描二维码，可以看到付款页面。</p>
<h2 id="3-4-付款状态查询"><a href="#3-4-付款状态查询" class="headerlink" title="3.4.付款状态查询"></a>3.4.付款状态查询</h2><p>跳转到支付页面后，我们等待用户付款，付款完成则跳转到付款成功页面。</p>
<h3 id="3-4-1-页面循环查询支付状态"><a href="#3-4-1-页面循环查询支付状态" class="headerlink" title="3.4.1.页面循环查询支付状态"></a>3.4.1.页面循环查询支付状态</h3><p>不过，因为不清楚用户何时会付款，因此这里采用循环的方式，不断请求判断是否支付成功。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 开启定时任务，查询付款状态</span></span><br><span class="line"><span class="keyword">const</span> taskId = <span class="built_in">setInterval</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    ly.http.get(<span class="string">&quot;/order/state/&quot;</span> + <span class="built_in">this</span>.orderId)</span><br><span class="line">        .then(<span class="function"><span class="params">resp</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">let</span> i = resp.data;</span><br><span class="line">        <span class="keyword">if</span> (i === <span class="number">1</span>) &#123;</span><br><span class="line">            <span class="comment">// 付款成功</span></span><br><span class="line">            <span class="built_in">clearInterval</span>(taskId);</span><br><span class="line">            <span class="comment">// 跳转到付款成功页</span></span><br><span class="line">            location.href = <span class="string">&quot;/paysuccess.html?orderId=&quot;</span> + <span class="built_in">this</span>.orderId;</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (i === <span class="number">2</span>) &#123;</span><br><span class="line">            <span class="comment">// 付款失败</span></span><br><span class="line">            <span class="built_in">clearInterval</span>(taskId);</span><br><span class="line">            <span class="comment">// 跳转到付款失败页</span></span><br><span class="line">            location.href = <span class="string">&quot;/payfail.html&quot;</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;, <span class="number">3000</span>);</span><br></pre></td></tr></table></figure>

<h3 id="3-4-2-付款成功页面"><a href="#3-4-2-付款成功页面" class="headerlink" title="3.4.2.付款成功页面"></a>3.4.2.付款成功页面</h3><p>当付款成功后，自动跳转到付款成功页面：</p>
<p><img src="assets/1528376883924.png" alt="1528376883924"></p>

            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        Author:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">AverageJoe</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        Link:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="http://www.averagejoe.top/2018/08/18/leyou/day19-bi-ji/day19-xia-dan/">http://www.averagejoe.top/2018/08/18/leyou/day19-bi-ji/day19-xia-dan/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        Reprint policy:
                    </i>
                </span>
                <span class="reprint-info">
                    All articles in this blog are used except for special statements
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    reprint polocy. If reproduced, please indicate source
                    <a href="/about" target="_blank">AverageJoe</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>Copied successfully, please follow the reprint policy of this article</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">more</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            <span class="chip bg-color">No tag</span>
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/medias/comment_bg.png") 100% 100% no-repeat;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 'BhOC9gMKAfPsRTjqr679tX7A-gzGzoHsz',
        appKey: 'xb9C1I9k62m6AJvin0UWGhSr',
        notify: 'false' === 'true',
        verify: 'false' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '10',
        lang: 'en',
        placeholder: 'just go go'
    });
</script>

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;Previous</div>
            <div class="card">
                <a href="/2018/08/19/leyou/day09-bi-ji/day09-shang-pin-gui-ge-guan-li/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/0.jpg" class="responsive-img" alt="">
                        
                        <span class="card-title"></span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            0.学习目标
了解商品规格数据结构设计思路
实现商品规格查询
了解SPU和SKU数据结构设计思路
实现商品查询
了解商品新增的页面实现
独立编写商品新增后台功能

1.商品规格数据结构乐优商城是一个全品类的电商网站，因此商品的种类繁多，每一
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2018-08-19
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            AverageJoe
                            
                        </span>
                    </div>
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                Next&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2018/08/14/leyou/day18-bi-ji/day18-gou-wu-che/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/0.jpg" class="responsive-img" alt="">
                        
                        <span class="card-title"></span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            0.学习目标1.搭建购物车服务1.1.创建module

1.2.pom依赖12345678910111213141516171819202122232425262728293031323334&lt;?xml version=&quot;
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2018-08-14
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            AverageJoe
                            
                        </span>
                    </div>
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;TOC</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">2019</span>
            <a href="/about" target="_blank">AverageJoe</a>
            |&nbsp;Powered by&nbsp;<a href="#" target="_blank">AverageJoe</a>
            |&nbsp;Theme&nbsp;<a href="#" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">213.1k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">


    <a href="mailto:1533360044@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1533360044" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1533360044" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;Search</span>
            <input type="search" id="searchInput" name="s" placeholder="Please enter a search keyword"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/search.xml", 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    
	

	<div id="weather-v2-plugin-simple"></div>
<script>
WIDGET = {
  CONFIG: {
    "modules": "0124",
    "background": 1,
    "tmpColor": "FFFFFF",
    "tmpSize": 16,
    "cityColor": "FFFFFF",
    "citySize": 16,
    "aqiSize": 16,
    "weatherIconSize": 24,
    "alertIconSize": 18,
    "padding": "10px 10px 10px 10px",
    "shadow": "1",
    "language": "auto",
    "borderRadius": 5,
    "fixed": "false",
    "vertical": "middle",
    "horizontal": "center",
    "key": "XZgo8dbNqo"
  }
}
</script>
<script src="https://apip.weatherdt.com/simple/static/js/weather-simple-common.js?v=2.0"></script>
<script src="/js/cursor.js"></script>
</body>

</html>
